package com.mumu.poi.excel;

import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.FontFormatting;

import java.io.FileOutputStream;

/**
 * @author mumu
 * @version 1.0
 * @date 2024/1/8 17:01
 * @describe
 */
public class FontGenerate {
    public static void main(String[] args) throws Exception {
        //文件路径
        String filePath = "excel/FontGenerate.xls";
        //创建Excel文件(Workbook)
        HSSFWorkbook workbook = new HSSFWorkbook();

        HSSFSheet sheet = workbook.createSheet("Test");// 创建工作表(Sheet)
        HSSFRow row = sheet.createRow(0);

        HSSFCell cell = row.createCell(1);
        cell.setCellValue("设置字体");
        HSSFCellStyle style = workbook.createCellStyle();
        HSSFFont font = workbook.createFont();
        font.setFontName("华文行楷");//设置字体名称
        font.setFontHeightInPoints((short) 28);//设置字号
        font.setColor(HSSFColor.HSSFColorPredefined.RED.getIndex());//设置字体颜色
        font.setUnderline(FontFormatting.U_SINGLE);//设置下划线
        font.setTypeOffset(FontFormatting.SS_SUPER);//设置上标下标
        font.setStrikeout(true);//设置删除线
        style.setFont(font);
        cell.setCellStyle(style);

        FileOutputStream out = new FileOutputStream(filePath);
        //保存Excel文件
        workbook.write(out);

        out.close();//关闭文件流
        System.out.println("OK!");

    }
}
